package com.alog.senior.day22;

import java.io.*;
import java.net.Socket;

/**
 * @Auther: Ye Zhengdong
 * @Date: 2019/1/25 11:07
 * @Description:
 */
public class TCPClient {
    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("127.0.0.1", 8888);
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d:\\sss.png"));
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
//        InputStream bis = new FileInputStream("d:\\sss.png");
//        OutputStream bos = socket.getOutputStream();
        byte[] buf = new byte[1024];
        int len = 0;
        while((len = bis.read(buf)) != -1){
            bos.write(buf, 0, len);
        }
        bos.flush();
        socket.shutdownOutput();

        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line = br.readLine();
        System.out.println(line);

//        InputStream in = socket.getInputStream();
//        byte[] buf2 = new byte[1024];
//        len = in.read(buf2);
//        String line = new String(buf2, 0, len);
//        System.out.println(line);

        socket.close();
    }
}
